package com.smugglersend.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;

/**
 * Created by Carlos on 4/5/14.
 */
public class SplashActivity extends Activity {

    // used to know if the back button was pressed in the splash screen activity and avoid opening the next activity
      private boolean mIsBackButtonPressed;
      private static final int SPLASH_DURATION = 2000; // 2 seconds


    /** Called when the activity is first created*/
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.splash_screen);

        Handler handler = new Handler();
        // run a thread after 2 seconds to start the home screen
        handler.postDelayed(new Runnable() {
            public void run() {
                // make sure we close the splash screen so the user won
                finish();
               if(!mIsBackButtonPressed) {
                    //start the home screen if the back button wasn't pressed
                    Intent mainIntent;
                    mainIntent = new Intent(SplashActivity.this,MainActivity.class);
                    SplashActivity.this.startActivity(mainIntent);
                    SplashActivity.this.finish();
                }
           }
        }, SPLASH_DURATION);

    }

    @Override
    public void onBackPressed() {
        // set the flag to true so the next activity won't startup
        mIsBackButtonPressed = true;
        super.onBackPressed();
    }
}
